package com.facemox.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import com.facemox.bean.PermissionAuthentication;

public interface AuthorizationMapper {
    // 1、插入一条FaceInfo数据
    @Insert("INSERT INTO face_authentication(authentication_type,authentication_name,access_token_url,username,password,token,remark) values(#{authenticationType},#{authorizationName},#{accessTokenUrl},#{username},#{password},#{token},#{remark})")
    // 1、获取数据库自增ID，keyProperty：java对象的属性，keyColumn：数据库字段名称
    @Options(useGeneratedKeys=true,keyProperty="authenticationId",keyColumn="authentication_id")
    int addAuthentication(PermissionAuthentication permissionAuthentication);
    
    // 2、查询全部权限
    @Select("select * from face_authentication")
    @Results({
        @Result(column = "authentication_id",property = "authenticationId"),
        @Result(column = "authentication_type",property = "authenticationType"),
        @Result(column = "access_token_url",property = "accessTokenUrl"),
        @Result(column = "authentication_name",property = "authorizationName"),
        @Result(column = "username",property = "username"),
        @Result(column = "password",property = "password"),
        @Result(column = "token",property = "token"),
        @Result(column = "remark",property = "remark")
    })
    List<PermissionAuthentication> findAuthorizationByAll();
    
    // 3、根据authenticationId查询face_authentication
    @Select("select * from face_authentication where authentication_id=#{authenticationId}")
    @Results({
        @Result(column = "authentication_id",property = "authenticationId"),
        @Result(column = "authentication_type",property = "authenticationType"),
        @Result(column = "access_token_url",property = "accessTokenUrl"),
        @Result(column = "authentication_name",property = "authorizationName"),
        @Result(column = "username",property = "username"),
        @Result(column = "password",property = "password"),
        @Result(column = "token",property = "token"),
        @Result(column = "remark",property = "remark")
    })
    PermissionAuthentication findAuthorizationByAuthenticationId(Integer authenticationId);
    
    // 4、根据id删除用户
    @Delete("delete from face_authentication where authentication_id=#{authenticationId}")
    int deleteAuthorizationById(Integer authenticationId);
}
